<?php
namespace App\Http\Controllers\Api;

use App\Http\Requests\API\CreateDeviceInspectRequest;
use App\Http\Requests\API\UpdateDeviceInspectRequest;
use App\Http\Controllers\AppBaseController;
use App\Models\DeviceInspector;
use Illuminate\Http\Request;

class DeviceInspectorController extends AppBaseController
{
    public function createInspectSettings(CreateDeviceInspectRequest $request)
    {
        if ($result = (new DeviceInspector)->createSetting($request->all())) {
            return $this->sendResponse($result, '创建设备维保配置成功');
        } else {
            return $this->sendError('创建设备维保配置失败');
        }
    }

    public function updateInspectSettings(UpdateDeviceInspectRequest $request)
    {
        if ($result = (new DeviceInspector)->updateSetting($request->except(['id']), $request->only(['id']))) {
            return $this->sendResponse($result, '更新设备维保配置成功');
        } else {
            return $this->sendError('更新设备维保配置失败');
        }
    }

    public function getInspectSettings(Request $request)
    {
        $where = $request->all();
        if (empty($where)) {
            return $this->sendError('获取维保配置失败');
        } else {
            return $this->sendResponse(DeviceInspector::where($where)->get()->toArray(), true);
        }
    }
}
